<admintpl file="header" />
<style type="text/css">
	.pic-list li {
		margin-bottom: 5px;
	}
	.label-td {
		position: relative;
	}
	.label-td .label-container {
		float: left;
		width: 90%;
		overflow: hidden;
		white-space: nowrap;
	}
	.label-td .label-select {
		float: right;
		font-size: 18px;
		display: inline-block;
		position: relative;
		padding-top: 10px;
	}
	.label-td .label-select:hover {
		color: #5bc0de;
	}
	.label-td .label-container span {
		display: inline-block;
		width: 80px;
		height: 30px;
		line-height: 30px;
		border: 1px solid #5bc0de;
		border-radius: 10px;
		text-align: center;
		margin-right: 10px;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
	.hidden_option {
		display: none;
	}
	input[type="radio"] + label::before {
		content: "\a0"; /*不换行空格*/
		display: inline-block;
		vertical-align: middle;
		font-size: 18px;
		width: 1em;
		height: 1em;
		margin-right: .4em;
		border-radius: 50%;
		border: 1px solid #01cd78;
		text-indent: .15em;
		line-height: 1;
	}
	input[type="radio"]:checked + label::before {
		background-color: #01cd78;
		background-clip: content-box;
		padding: .2em;
	}
	input[type="radio"] {
		position: absolute;
		clip: rect(0, 0, 0, 0);
	}

</style>
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('Lesson/Adminlesson/lesson_lists')}">课程列表</a></li>
			<li class="active"><a href="#">编辑课程</a></li>
		</ul>
		<form action="{:U('Lesson/Adminlesson/edit_lesson')}" method="post" class="form-horizontal js-ajax-forms" enctype="multipart/form-data">
			<div class="row-fluid">
				<div class="span9">
					<table class="table table-bordered">
						<tr>
							<th>课程名称</th>
							<td>
								<input type="hidden" name="lesson[id]" value="{$lesson.id}">
								<input type="text" style="width: 400px;" name="lesson[lesson_name]" required value="{$lesson.lesson_name}" placeholder="请输入课程名称"/>
								<span class="form-required">*</span>
							</td>
						</tr>
						<tr>
							<th>标签</th>
							<td class="label-td">
								<div class="label-container">
									<input type="hidden" value="{$lesson['labels']}" name="lesson[labels]" id="labels">
									<volist name="lesson[label_names]" id="vo">
										<span class="label-name">{$vo}</span>
									</volist>
								</div>
								<div class="label-select">
									<span class="label-select-span">选择标签</span>
								</div>
							</td>
						</tr>
						<tr>
							<th>课程专题</th>
							<td>
								<select name="lesson[subject_id]" id="subject_id">
									<option value="0">请选择课程专题</option>
									<volist name="subject_lists" id="vo">
										<option value="{$vo.id}" {$vo['id'] == $lesson['subject_id'] ? 'selected' : ''}>{$vo.subject_name}</option>
									</volist>
								</select>
							</td>
						</tr>
						<tr>
							<th>课程行家</th>
							<td>
								<select name="lesson[lecturer_user_id]" id="lecturer_user_id">
									<option value="0">请选择课程行家</option>
									<volist name="professor_lists" id="vo">
										<option class="pf_option" value="{$vo.id}" {$vo['id'] == $lesson['lecturer_user_id'] ? 'selected' : ''}>{$vo.user_nicename|default=$vo['user_login']}</option>
									</volist>
								</select>
								<input type="text" id="professor_search_input" placeholder="输入行家名称模糊搜索">
							</td>
						</tr>
						<tr>
							<th>课程视频名称</th>
							<td>
								<select name="lesson[lesson_video_id]" id="lesson_video_id">
									<option value="0">请选择视频</option>
									<volist name="video_lists" id="vo">
										<option class="vl_option" value="{$vo.id}" {$vo['id'] == $lesson['lesson_video_id'] ? 'selected' : ''}>{$vo.video_name}</option>
									</volist>
								</select>
								<input type="text" id="video_search_input" placeholder="输入视频名称模糊搜索">
							</td>
						<tr>
							<th>免费试看</th>
							<td>
								<select name="lesson[free]">
									<option value="0" {$lesson['free'] == 0 ? 'selected' : ''}>否</option>
									<option value="1" {$lesson['free'] == 1 ? 'selected' : ''}>是</option>
								</select>
							</td>
						</tr>
					</table>
				</div>
				<div class="span3">
					<table class="table table-bordered">
						<tr>
							<td><b>缩略图</b></td>
						</tr>
						<tr>
							<td>
								<div style="text-align: center;">
									<input type="hidden" name="smeta[thumb]" id="thumb" value="{$lesson.lesson_img|default=''}">
									<a href="javascript:upload_one_image('图片上传','#thumb');">
										<if condition="empty($lesson['lesson_img'])">
											<img src="__TMPL__Public/assets/images/default-thumbnail.png" id="thumb-preview" width="135" style="cursor: hand"/>
										<else />
											<img src="{:sp_get_image_preview_url($lesson['lesson_img'])}" id="thumb-preview" width="135" style="cursor: hand"/>
										</if>
									</a>
									<input type="button" class="btn btn-small" onclick="$('#thumb-preview').attr('src','__TMPL__Public/assets/images/default-thumbnail.png');$('#thumb').val('');return false;" value="取消图片">
								</div>
							</td>
						</tr>
						<tr>
							<td><b>音频背景图</b></td>
						</tr>
						<tr>
							<td>
								<div style="text-align: center;">
									<input type="hidden" name="smeta[audio_thumb]" id="audio_thumb" value="{$lesson.lesson_audio_img|default=''}">
									<a href="javascript:upload_one_image('图片上传','#audio_thumb');">
										<if condition="empty($lesson['lesson_audio_img'])">
											<img src="__TMPL__Public/assets/images/default-thumbnail.png" id="audio_thumb-preview" width="135" style="cursor: hand"/>
											<else />
											<img src="{:sp_get_image_preview_url($lesson['lesson_audio_img'])}" id="audio_thumb-preview" width="135" style="cursor: hand"/>
										</if>
									</a>
									<input type="button" class="btn btn-small" onclick="$('#audio_thumb-preview').attr('src','__TMPL__Public/assets/images/default-thumbnail.png');$('#thumb').val('');return false;" value="取消图片">
								</div>
							</td>
						</tr>
						<tr>
							<td><b>课程文稿</b></td>
						</tr>
						<tr>
							<td>
								<div style="text-align: center;">
									<input type="hidden" name="lesson[lesson_file_path]" id="lesson_file_path" value="{$lesson['lesson_file']['lesson_file_path']|default=''}">
									<input type="text" name="lesson[lesson_file_name]" id="lesson_file_name" value="{$lesson['lesson_file']['lesson_file_name']}" style="width: 95%;">
								</div>
								<br>
								<a href="javascript:upload_one_file('文件上传', '#lesson_file');">
									<input type="button" id="lesson_file" value="上传文稿">
								</a>
								<input type="button" class="btn btn-small" onclick="$('#lesson_file_name').val('');$('#lesson_file_path').val('');return false;" value="取消文件">
							</td>
						</tr>
					</table>
				</div>
			</div>
			<div class="form-actions">
				<button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
				<a class="btn" href="{:U('Lesson/Adminlesson/lesson_lists')}">返回</a>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript">
		//编辑器路径定义
		var editorURL = GV.WEB_ROOT;
	</script>
	<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.config.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/ueditor/ueditor.all.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/layer/layer_1.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/notify.js"></script>
	<script type="text/javascript">
		$(function() {
		    // 模糊搜索
			$('#professor_search_input').keyup(function () {
			    var search = $(this).val();
			    $('.pf_option').each(function () {
			        $(this).removeClass('hidden_option');
			        var pf_name = $(this).text();
			        if (pf_name.search(search) < 0) {
			            $(this).addClass('hidden_option');
					}
                });
            });
            $('#video_search_input').keyup(function () {
                var search = $(this).val();
                $('.vl_option').each(function () {
                    $(this).removeClass('hidden_option');
                    var vf_name = $(this).text();
                    if (vf_name.search(search) < 0) {
                        $(this).addClass('hidden_option');
                    }
                });
            });

            $('#lesson_video_id').change(function () {
				$('#lesson_video_url').val('');
            });
			$('#lesson_video_url').focus(function () {
                $('#lesson_video_id').val(0);
            });

		    // 选择标签
            $('.label-select-span').click(function () {
                var has_labels = $('#labels').val();
                layer.open({
                    title: "选择标签",
                    type: 2,
                    area: ['70%', '70%'],
                    btn: ['确定', '取消'],
                    content: "{:U('Label/AdminIndex/select_label')}" + "&has_labels=" + has_labels,
                    yes:function (index, layerC) {
                        // 子窗口
                        var content 	= layerC.find("iframe")[0].contentWindow;
                        var labels 		= content.$('#has_labels').val();

                        $('#labels').val(labels);
                        $.get("{:U('Label/AdminIndex/get_label_name')}" + "&label_ids=" + labels, {}, function (data) {
                            if (data.status) {
                                $('.label-name').remove();
                                var html = "";
                                $.each(data.data, function (index, item) {
                                    html += '<span class="label-name">';
                                    html += item.name;
                                    html += '</span>';
                                })
                                $('.label-container').append(html);
                            }
                        })

                        layer.close(index);
                    }
                });
            });
			/////---------------------
			Wind.use('validate', 'ajaxForm', 'artDialog', function() {
				var form = $('form.js-ajax-forms');
				//ie处理placeholder提交问题
				if ($.browser && $.browser.msie) {
					form.find('[placeholder]').each(function() {
						var input = $(this);
						if (input.val() == input.attr('placeholder')) {
							input.val('');
						}
					});
				}
				//表单验证开始
				form.validate({
					//是否在获取焦点时验证
					onfocusout : false,
					//是否在敲击键盘时验证
					onkeyup : false,
					//当鼠标掉级时验证
					onclick : false,
					//验证错误
					showErrors : function(errorMap, errorArr) {
						//errorMap {'name':'错误信息'}
						//errorArr [{'message':'错误信息',element:({})}]
						try {
							$(errorArr[0].element).focus();
							art.dialog({
								id : 'error',
								icon : 'error',
								lock : true,
								fixed : true,
								background : "#CCCCCC",
								opacity : 0,
								content : errorArr[0].message,
								cancelVal : '确定',
								cancel : function() {
									$(errorArr[0].element).focus();
								}
							});
						} catch (err) {
						}
					},
					//验证规则
					rules : {
						'lesson[lesson_name]' : {
							required : 1
						},
						'lesson[subject_id]' : {
                            required : 1
						},
                        'lesson[lecturer_user_id]' : {
                            required : 1
                        },
					},
					//验证未通过提示消息
					messages : {
						'lesson[lesson_name]' : {
							required : '请输入课程名称'
						},
						'lesson[subject_id]' : {
                            required : '请输入课程专题'
						},
                        'lesson[lecturer_user_id]' : {
                            required : '请输入课程行家'
                        },
					},
					//给未通过验证的元素加效果,闪烁等
					highlight : false,
					//验证通过，提交表单
					submitHandler : function(forms) {
						$(forms).ajaxSubmit({
							url : form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
								dataType : 'json',
								beforeSubmit : function(arr, $form, options) {
							},
							success : function(data, statusText, xhr, $form) {
								if (data.status) {
									setCookie("refersh_time", 1);
									//添加成功
									Wind.use("artDialog", function() {
										art.dialog({
											id : "succeed",
											icon : "succeed",
											fixed : true,
											lock : true,
											background : "#CCCCCC",
											opacity : 0,
											content : data.info,
											button : [ {
												name : '继续编辑？',
												callback : function() {
													reloadPage(window);
													return true;
												},
												focus : true
											}, {
												name : '返回列表页',
												callback : function() {
													location = "{:U('Lesson/Adminlesson/lesson_lists')}";
													return true;
												}
											} ]
										});
									});
								} else {
									artdialog_alert(data.info);
								}
							}
						});
					}
				});
			});
		});
	</script>
</body>
</html>